package com.codegeek.project.monitor.controller;

import com.codegeek.common.utils.poi.ExcelUtil;
import com.codegeek.framework.aspectj.lang.annotation.Log;
import com.codegeek.framework.aspectj.lang.enums.BusinessType;
import com.codegeek.framework.web.controller.BaseController;
import com.codegeek.framework.web.domain.AjaxResult;
import com.codegeek.framework.web.page.TableDataInfo;
import com.codegeek.project.monitor.domain.SysOperLog;
import com.codegeek.project.monitor.domain.SysOperLogExcelResult;
import com.codegeek.project.monitor.service.ISysOperLogService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.LinkedList;
import java.util.List;

/**
 * 操作日志记录
 *
 * @author codegeek
 */
@RestController
@RequestMapping("/monitor/operlog")
public class SysOperlogController extends BaseController
{
    @Autowired
    private ISysOperLogService operLogService;

    @GetMapping("/list")
    @PreAuthorize("@ss.hasPermi('monitor:operlog:list')")
    public TableDataInfo list(SysOperLog operLog)
    {
        startPage();
        List<SysOperLog> list = operLogService.selectOperLogList(operLog);
        return getDataTable(list);
    }

    @Log(title = "操作日志", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    @PreAuthorize("@ss.hasPermi('monitor:operlog:export')")
    public AjaxResult export(SysOperLog operLog)
    {
        List<SysOperLog> list = operLogService.selectOperLogList(operLog);
        List<SysOperLogExcelResult> sysOperLogExcelResults = new LinkedList<>();
        for (SysOperLog sysOperLog : list) {
            SysOperLogExcelResult sysOperLogExcelResult = new SysOperLogExcelResult();

            sysOperLogExcelResult.setOperId(sysOperLog.getOperId());
            sysOperLogExcelResult.setOperName(sysOperLog.getOperName());
            sysOperLogExcelResult.setRoleName(sysOperLog.getRoleName());
            sysOperLogExcelResult.setTitle(sysOperLog.getTitle());
            sysOperLogExcelResult.setBusinessType(sysOperLog.getBusinessType());
            sysOperLogExcelResult.setOperIp(sysOperLog.getOperIp());
            sysOperLogExcelResult.setOperTime(sysOperLog.getOperTime());

            sysOperLogExcelResults.add(sysOperLogExcelResult);
        }
        ExcelUtil<SysOperLogExcelResult> util = new ExcelUtil<>(SysOperLogExcelResult.class);
        return util.exportExcel(sysOperLogExcelResults, "操作日志");
    }

//    public AjaxResult remove(@PathVariable Long[] operIds)
//    {
//        return toAjax(operLogService.deleteOperLogByIds(operIds));
//    }
//
//    @Log(title = "操作日志", businessType = BusinessType.CLEAN)
//    public AjaxResult clean()
//    {
//        operLogService.cleanOperLog();
//        return AjaxResult.success();
//    }
}
